I'm very new to programming and very very new to Java, so I'm sure this question (and all my other mistakes) will be very obvious to anyone with experience. I clearly don't know what I'm doing. My assignment was to convert Python code to Java. Below is my code.
My two error codes are:
Assignment1.java:37: error: incompatible types: String cannot be
converted to int
response = reader.nextLine();
Assignment1.java:38: error: incompatible types: int cannot be converted to String
num = Integer.parseInt(response);
For clarification, I'm using JGrasp, but willing to not.
import java.util.Scanner;
public class Assignment1 {
public static void main(String[] args) {
int num, response, min, max, range, sum, count, avg;
Scanner reader = new Scanner(System.in);
String reportTitle;
//title
System.out.println();
System.out.println("Enter a title for this report");
reportTitle = reader.nextLine();
System.out.println();
//data input
System.out.println("Enter a series of numebr, ending with a 0");
num = 0;
sum = 0;
response = 1;
count = 0;
max = 0;
min = 0;
range = 0;
while (true)
{
if (response < 1)
{
System.out.println("End of Data");
break;
}
System.out.println("Enter number => ");
response = reader.nextLine();
num = Integer.parseInt(response);
sum += num;
count += 1;
if (num>max)
{
max = num;
}
if (num<min)
{
min = num;
}
}
//crunch
avg = sum / count;
range = max - min;
//report
System.out.println();
System.out.println(reportTitle);
System.out.println();
System.out.println("Sum: => "+sum);
System.out.println("Average: => "+avg);
System.out.println("Smallest: => "+min);
System.out.println("Largest: => "+max);
System.out.println("Range: => "+range);
}
}