Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I combine strings and integers in a print statement?
    primarykey
    data
    text
    <p>I have just started learning Java in a college course. If/then statements haven't been covered yet but I figured I could try them on my own. I ended up with some syntax errors which I think I fixed, but now it seems like there are operand errors when I try adding a string with integers. </p> <p>The problem given in my class was to ask the user for their name, hourly rate of pay, and how many hours they worked. I know the professor will soon ask us to ask the user if they get paid overtime. If they do, ask after how many hours overtime is paid. And then calculate the total payment, with any overtime pay being 1.5x of the regular hourly rate.</p> <p>However I get an error in the last 3 print statements, which I assume is because I am trying to combine a string and an integer. How do I fix this? </p> <pre><code>package javaapplication2; import java.util.Scanner; public class JavaApplication2 { public static void main(String [] args) { Scanner input = new Scanner(System.in); String name; double payRate; int hours; Boolean OTyn; int OTy; System.out.println("What is your name?"); name = input.nextLine(); System.out.println("What is your hourly rate of pay?"); payRate = input.nextDouble(); System.out.println("How any hours have you worked?"); hours = input.nextInt(); System.out.println("Your boss pays overtime. Answer with true or false."); OTyn = input.nextBoolean(); if (OTyn == true) System.out.println("After how many hours are you paid for overtime?"); OTy = input.nextInt(); if (hours &gt; OTy) System.out.println("Your weekly pay is " + ((40 * payRate) + (hours - OTy)(payRate * 1.5))); else System.out.println("Your weekly pay is " + payRate * hours); else System.out.println("Your weekly pay is " + payRate * hours); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload