• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Rob Spoor
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Himai Minh

Ternary operators

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
write  a  java program  TO get a number from the user TO print  whether it is positive OR negative using ternary operators
 
Saloon Keeper
Posts: 8457
71
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to The Ranch! Do you have a specific question? Do you know what a ternary operator is?
 
Master Rancher
Posts: 4461
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What have you tried?  Please post your code wrapped in code tags.
 
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
return isHomeworkQuestion(post) ? null : provideDetailedResponse()

Please post up some code you wrote and I'll try to help out.
 
Carey Brown
Saloon Keeper
Posts: 8457
71
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Likes 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
return isHomeworkQuestion(post) ? null : provideDetailedResponse()provideHelpfulHintsAndGuidance()
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Marshal
Posts: 73766
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch (again)

What are you going to do if the user enters 0 or 0.0?
 
Campbell Ritchie
Marshal
Posts: 73766
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
MB: welcome to the Ranch

Please look at the contents page for this forum, where it says

We're all here to learn, so when responding to others, please focus on helping them discover their own solutions, instead of simply providing answers.

It doesn't help anybody to be given a complete solution; nobody learns like this. I have therefore removed your solution and the forum software records it somewhere.
As I mentioned earlier, your solution doesn's handle zero.
 
Marshal
Posts: 22409
121
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

throw new IfCampbellSeesThisCompleteSolutionHellDeleteItException();


Hell is going to delete complete solutions? Wow!
 
Campbell Ritchie
Marshal
Posts: 73766
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hahahahahahahahahaha!
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
import java.util.*;

public class Brainly

{

static void main()

{

Scanner sc=new Scanner(System.in);

int n;

System.out.print("Enter an integer: ");

n=sc.nextInt();

System.out.println((n>0)?"Positive":(n<0)?"Negative":"Zero");

}

}

 
Campbell Ritchie
Marshal
Posts: 73766
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

Please always indent code correctly and don't double‑space it. When you have done that, the code button will make the code look better still, as above. Please also put spaces around your operators; you only got because you didn't space the code out enough.
 
passwords must contain 14 characters, a number, punctuation, a small bird, a bit of cheese and a tiny ad.
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic