Results 1 to 3 of 3
  1. #1
    p0intblankk is offline Member
    Join Date
    Sep 2011
    Location
    Arizona
    Posts
    1
    Rep Power
    0

    Default For Loop For CSC110 Class..Need some help.

    Need help in finishing my program....I have questions one and two answered but I need to implement question number three into my program.
    I've established the first table of the degrees and asking the user for input. What I don't understand is how to implement the second for loop into my program and prompt the user to put in values to raise by a power.
    Any help on how to program question three of my assignment would be much appreciated.
    Thanks in advance.


    Here's the detail on the assignment.
    CSC110
    In Class
    Loops 1
    1. Write a program that displays a temperature conversion chart on the screen as
    follows:
    Fahrenheit Celsius Absolute Value
    0 -17.78 255.37
    20 -6.67 266.48
    40 4.44 277.59
    ... ...... ......
    ... ...... ......
    300 148.89 422.04
    -To convert temperatures written in Fahrenheit to Celsius you subtract 32, multiply
    by 5 and then divide by 9. To convert Celsius to Absolute Value (Kelvin), you add
    273.15
    2. Alter the program for question 1 so that it prompts the user for the lowest and
    highest Fahrenheit temperature wanted in the table, and also prompts the user
    for the desired step size between rows of the table (the step size is 20 in question
    1). The program should begin by explaining to the user what it does, and should
    appropriately echo the user's input before printing the table.
    3. Write a program which will raise any number x to a positive power n using a for
    loop. You will be getting x from the user.

    --------------------------------------… is what i have so far......Loop.java
    Java Code:
    import java.util.Scanner;
    public class Looping
    {
    public static void main( String[] args )
    {
    System.out.println("What is the lowest fahrenheit value you want in your table?");
    int a;
    Scanner input= new Scanner(System.in);
    a= input.nextInt();
    System.out.println("What is the highest fahrenheit value you want in your table?");
    int m;
    m= input.nextInt();
    System.out.println("What do you want the values to step by?");
    int p;
    p= input.nextInt();
    
    {
    
    System.out.println("Fahrenheit " + " Celsius " +" Absolute Value ");
    double y;
    double z;
    
    for(int i=a; i<=m;i+=p)
    {
    
    y=(((double)i-32)*5)/9;
    z=((y+273));
    
    System.out.println(i+" "+ y +" "+ z );
    
    
    }
    
    
    
    
    
    }
    
    
    
    }
    }
    Last edited by p0intblankk; 09-06-2011 at 04:39 AM.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: For Loop For CSC110 Class..Need some help.

    Please edit your post and change your quote tags to code tags so that your code will be readable.

    I don't see above where you've attempted to solve number 3, nor where you ask a specific question about what you don't understand. Please do one or both so that we know how to help you.

  3. #3
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,784
    Rep Power
    7

    Default Re: For Loop For CSC110 Class..Need some help.

    Quote Originally Posted by p0intblankk View Post
    You will be getting x from the user.
    What about n?

Similar Threads

  1. Loop + inner class error
    By snaquetime in forum New To Java
    Replies: 4
    Last Post: 08-30-2011, 05:42 AM
  2. JTextField loop 2x for-loop WEIRD!
    By Streetproject in forum AWT / Swing
    Replies: 2
    Last Post: 02-16-2011, 05:46 PM
  3. Convert do while loop to for loop
    By sandeeptheviper in forum New To Java
    Replies: 3
    Last Post: 01-03-2011, 12:37 PM
  4. Scanner class in my for loop
    By Mode in forum New To Java
    Replies: 1
    Last Post: 12-20-2010, 09:48 AM
  5. Replies: 0
    Last Post: 12-11-2009, 10:26 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •